package com.xyj.concurrent;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @author GuXiaoYao
 * @version 1.0.0
 * @since 2021/9/9
 */
public class T2 {

    public static void main(String[] args) {
        CyclicBarrier cyclicBarrier=new CyclicBarrier(6);

        for (int i = 0; i <6 ; i++) {
            new Thread(()->{
                System.out.println(Thread.currentThread().getName()+"我准备好了");
                try {
                    cyclicBarrier.await();
                    System.out.println(Thread.currentThread().getName()+"开启冲刺");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            },"线程"+i).start();
        }
    }
}
